package com.zoe.onelink.doc.plugin.feign.model;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.Map;

/**
 * <p>标题: </p>
 * <p>描述: </p>
 * <p>版权: Copyright (c) 2022</p>
 * <p>公司: 智业软件股份有限公司</p>
 *
 * @version: 1.0
 * @author: ruansheng
 * @date: 2022-03-31
 */
@Data
@Accessors(chain = true)
public class FeignClientTemplateParam {

    private String clientServiceName;
    private String clientUrl;
    private String path;
    private String clientName;
    private String requestMapping;
    private String mappingUrl;
    private String resultType;
    private String methodName;
    private String args;
    private String createdDate;

    public String toTemplateText(String template) {
        JSONObject jsonParam = JSONUtil.parseObj(this);
        for (Map.Entry<String, Object> e : jsonParam.entrySet()) {
            String key = String.format("${%s}", e.getKey());
            Object objVal = e.getValue();
            String value = objVal == null ? "" : objVal.toString();
            template = template.replace(key, value);
        }
        return template;
    }

}
